function getLongStr(s1, s2) {
    const m = s1.length;
    const n = s2.length;
    const dp = new Array(m + 1).fill(0).map(() => new Array(n + 1).fill(0));

    for (let i = 1; i <= m; i++) {
        for (let j = 1; j <= n; j++) {
            if (s1[i - 1] === s2[j - 1]) {
                dp[i][j] = dp[i - 1][j - 1] + 1;
            } else {
                dp[i][j] = Math.max(dp[i][j - 1], dp[i - 1][j]);
            }
        }
    }

    let i = m, j = n, res = '';
    while (i > 0 && j > 0) {
        if (s1[i - 1] === s2[j - 1]) {
            res = s1[i - 1] + res;
            i--;
            j--;
        } else if (dp[i - 1][j] > dp[i][j - 1]) {
            i--;
        } else {
            j--;
        }
    }
    return res;
}

let s1 = 'ababc';
let s2 = 'aba';
console.log(getLongStr(s1, s2)); // Output: 'a'

function strFn(s1,s2){
    const m = s1.length
    const n = s2.length
    const dp = new Array(m+1).fill(0).map(()=>new Array(n+1).fill(0))
    for(let i=1;i<=m;i++){
        for(let j=1;j<=n;j++){
            if(s1[i-1]===s2[j-1]){
                dp[i][j] = dp[i-1][j-1]+1
            }else{
                dp[i][j] = Math.max(dp[i-1][j],dp[i][j-1])
            }
        }
    }
    let i = m,j=n,res = ''
    while(i>0&&j>0){
        if(s1[i-1]===s2[j-1]){
            res = res+s1[i-1]
            i--
            j--
        }else if(dp[i-1][j]>dp[i][j-1]){
            i--
        }else{
            j--
        }
    }
    return res
}
console.log(strFn(s1, s2)); // Output: 'a'